import { reactive } from "vue";
import { me, update } from "@/api/auth/user";
import { ElMessage } from "element-plus";

export const _$ = reactive({
  requestParam: {
    id: null,
    birthday: "",
    email: "",
    gender: 0,
    name: "",
    phone: "",
  },
  responseParam: {},
  rules: reactive({}),
});

export const $ = {
  async onSubmit(formEl) {
    if (!formEl) {
      return;
    }
    await formEl.validate((valid, fields) => {
      if (valid) {
        update(_$.requestParam).then((_) => {
          ElMessage({
            message: "更新成功",
            type: "success",
          });
        });
      }
    });
  },

  loadEdit() {
    me().then((data) => {
      _$.requestParam = data;
    });
  },

  clean() {
    _$.requestParam = {};
  },
};

export const to = {};
